﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Threading.Tasks;
using System.Threading;
using Ninject;
using Example.Base.Interfaces.Services.DataServices;
using Example.Data.Services.DataServices;
using Example.Base.Entities;
using Example.Site.Models;

namespace Example.Site.Controllers.Api
{
    public class DataController:  BaseApiController
    {
        [Inject]
        public IDataService<Region> WeatherService { get; set; }

        [Inject]
        public IDataService<IEnumerable<Tweet>> TwitterService { get; set; }
             

        /// <summary>
        /// Get weather forecast and tweets from twitter by query
        /// </summary>
        /// <param name="model">Request model</param>
        /// <returns></returns>
        public HttpResponseMessage Get([FromUri]GetModel model)
        {
            return CreateResponse<GetModel, GetModel>(privateGet, model);
        }
        private GetModel privateGet(GetModel model)
        {
            var getWeather = WeatherService.AsyncGet();
            var getTwitts = TwitterService.AsyncGet(model.Query);

            model.Region = getWeather.Result;
            model.Tweets = getTwitts.Result;

            return model;
        }

    }
}
